﻿using System;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TeacherHelp.Util;

namespace TeacherHelp
{

    static class Program
    {
        public static int? UserId = null;
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //创建快捷方式
            CreateShortcut();
            StringBuilder sb = new StringBuilder("\n");
            sb.Append("=========================================\n");
            sb.Append("           欢迎来到教师好助手！            \n");
            sb.Append("=========================================");
            Log.Debug(sb.ToString());
            try
            {
                var loginForm = new FormList.LoginForm();
                loginForm.ShowDialog();
                Application.Run(loginForm.OpenForm);
            }
            catch (Exception ex)
            {
                Log.Critical("严重警告！ Application出现异常！", ex);
                Application.ExitThread();
            }


        }

        /// <summary>
        /// 创建快捷方式
        /// </summary>
        static void CreateShortcut()
        {
            if (Public.ConfigHelper.isBuilderShortcut)
            {
                //创建快捷方式
                Task.Run(() =>
                {
                    try
                    {
                        Log.Info("创建快捷方式中...");
                        ShortCutHelper.CreateShortcutOnDesktop("教师好助手", System.Environment.CurrentDirectory + "\\TeacherHelp.exe");
                        Log.Info("创建快捷方式成功！");
                    }
                    catch (Exception ex)
                    {
                        Log.Error($"创建快捷方式出现异常! 异常信息：{ex}");
                    }

                });
            }
        }
    }
}
